package cn.itcast.bos.service.bc.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.bc.RegionDao;
import cn.itcast.bos.domain.bc.Region;
import cn.itcast.bos.service.bc.RegionService;

@Service("regionService")
@Transactional
public class RegionServiceImpl implements RegionService {
	@Autowired
	private RegionDao regionDao;

	public void importData(List<Region> regions) {
		regionDao.save(regions);
	}

	public Region findRegionById(String id) {
		return regionDao.findOne(id);
	}

	public List<Region> findAll() {
		// TODO Auto-generated method stub
		return regionDao.findAll();
	}

	public List<Region> findAll(String paramValue) {
		if (StringUtils.isBlank(paramValue)) {
			return findAll();
		} else {
			// 模糊查询 实现 ..
			return regionDao.findByProviceOrCityOrDistrict("%" + paramValue + "%");
		}
	}

	public List<String> findAllProvince() {
		// TODO Auto-generated method stub
		return regionDao.findAllProvince();
	}

	public List<String> findAllCity(String province) {
		// TODO Auto-generated method stub
		return regionDao.findAllCity(province);
	}

	public List<String> findAllDistrict(String city) {
		// TODO Auto-generated method stub
		return regionDao.findAllDistrict(city);
	}

}
